package main

import (
	"log"

	"github.com/micro/go-micro"
	"git.oschina.net/fanbuchi/xgggh/order/handler"
	"git.oschina.net/fanbuchi/xgggh/order/subscriber"

	order "git.oschina.net/fanbuchi/xgggh/order/proto/order"
)

func main() {
	// New Service
	service := micro.NewService(
		micro.Name("com.xgggh.srv.order"),
		micro.Version("latest"),
	)

	// Register Handler
	order.RegisterOrdersHandler(service.Server(), new(handler.Order))

	// Register Struct as Subscriber
	service.Server().Subscribe(
		service.Server().NewSubscriber("topic.com.xgggh.srv.order", new(subscriber.Example)),
	)

	// Register Function as Subscriber
	service.Server().Subscribe(
		service.Server().NewSubscriber("topic.com.xgggh.srv.order", subscriber.Handler),
	)

	// Initialise service
	service.Init()

	// Run service
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}
